import java.io.*;
import java.util.*;

class MyName implements Comparable<MyName>{
  String name;
public int compareTo(MyName a)
  {
    if (this.name.compareTo(a.name)>0)
    return 1;
    else if (this.name.compareTo(a.name)<0)
    return -1;
    else return 0;
  }
  public boolean equals(Object obj)
  {
	  if (obj instanceof MyName) {
		 MyName a = (MyName)obj;
		return (a.toString().equals(toString()));
	  }
		else {  
			return false;  
		} 
}

  public int hashCode(){
	return name.hashCode();
  }
  public String toString()
	{
	  return (name);
	}
}






public class TestList
{
	List<MyName> c = new LinkedList<MyName>();
	public static void main(String[] args) {
	TestList t = new TestList();
    t.choose();
  }
    void choose()
    {
      System.out.println("输入1并回车开始录入数据\n输入2并回车检查数据输入");
      System.out.println("输入3并回车开始删除指定数据\n输入4并回车开始修改指定Key所对应的Value");
      System.out.println("输入5并回车，清空所有输入");
      System.out.println("输入6并回车，退出程序");
      Scanner sc = new Scanner(System.in);
      int choose=sc.nextInt();
      switch (choose) {
        case 1: addone();choose();break;
        case 2: listall();choose();break;
        case 3: removeone();choose();break;
        case 4: modone();choose();break;
        case 5: clearall();choose();break;
        case 6: System.exit(-1);break;
      }
	 }
  void addone()
  {
    MyName a = new MyName();
    Scanner sc = new Scanner(System.in);
    System.out.println("请输入想要添加的姓名");
    a.name = sc.next();
    c.add(a);
  }
    void removeone()
    {
      MyName p = new MyName();
      Scanner sc = new Scanner(System.in);
      System.out.println("请输入想要删除的姓名");
      p.name = sc.next();
      int i;
	  System.out.println("\tc.tostr:"+c.toString()+"\n\tp.toStr:"+p.toString());
	  i = c.indexOf(p);
	  System.out.println("\ti=="+i);
	  if (i==-1)
	  {
		  System.out.println("未找到该元素");
	  }
	  else c.remove(i);
    }
  void modone()
  {
    removeone();
    addone();
  }
  void listall()
	{
		System.out.println(c);
	}
  void clearall()
  {
    c.clear();
  }
}
